home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / nethack.lha / nethack-3.1 / win / X11 / winval.c < prev    next >
C/C++ Source or Header  |  1992-09-21  |  4KB  |  159 lines

  1. /*    SCCS Id: @(#)winval.c    3.1    92/3/7
  2. /* Copyright (c) Dean Luick, 1992                  */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /*
  6.  * Routines that define a name-value label widget pair that fit inside a
  7.  * form widget.
  8.  */
  9. #include <stdio.h>
  10. #include <X11/Intrinsic.h>
  11. #include <X11/StringDefs.h>
  12. #include <X11/Xaw/Label.h>
  13. #include <X11/Xaw/Form.h>
  14. #include <X11/Xaw/Cardinals.h>
  15.  
  16. #include "config.h"    /* #define for const for non __STDC__ compilers */
  17.  
  18. #define NAME "name"
  19. #define VALUE "value"
  20.  
  21.  
  22. Widget
  23. create_value(parent, name_value)
  24.     Widget parent;
  25.     const char *name_value;
  26. {
  27.     Widget form, name;
  28.     Arg args[8];
  29.     Cardinal num_args;
  30.  
  31.     num_args = 0;
  32.     XtSetArg(args[num_args], XtNborderWidth, 0);        num_args++;
  33.     XtSetArg(args[num_args], XtNdefaultDistance, 0);        num_args++;
  34.     form = XtCreateManagedWidget(name_value,
  35.                 formWidgetClass,
  36.                 parent, args, num_args);
  37.  
  38.     num_args = 0;
  39.     XtSetArg(args[num_args], XtNjustify, XtJustifyRight);    num_args++;
  40.     XtSetArg(args[num_args], XtNborderWidth, 0);        num_args++;
  41.     XtSetArg(args[num_args], XtNlabel, name_value);        num_args++;
  42.     XtSetArg(args[num_args], XtNinternalHeight, 0);        num_args++;
  43.     name = XtCreateManagedWidget(NAME,
  44.                 labelWidgetClass,
  45.                 form, args, num_args);
  46.  
  47.     num_args = 0;
  48.     XtSetArg(args[num_args], XtNjustify, XtJustifyRight);    num_args++;
  49.     XtSetArg(args[num_args], XtNborderWidth, 0);        num_args++;
  50.     XtSetArg(args[num_args], XtNfromHoriz, name);        num_args++;
  51.     XtSetArg(args[num_args], XtNinternalHeight, 0);        num_args++;
  52.     (void) XtCreateManagedWidget(VALUE,
  53.                 labelWidgetClass,
  54.                 form, args, num_args);
  55.     return form;
  56. }
  57.  
  58. void
  59. set_name(w, new_label)
  60.     Widget w;
  61.     char *new_label;
  62. {
  63.     Arg args[1];
  64.     Widget name;
  65.  
  66.     name = XtNameToWidget(w, NAME);
  67.     XtSetArg(args[0], XtNlabel, new_label);
  68.     XtSetValues(name, args, ONE);
  69. }
  70.  
  71. void
  72. set_name_width(w, new_width)
  73.     Widget w;
  74.     int new_width;
  75. {
  76.     Arg args[1];
  77.     Widget name;
  78.  
  79.     name = XtNameToWidget(w, NAME);
  80.     XtSetArg(args[0], XtNwidth, new_width);
  81.     XtSetValues(name, args, ONE);
  82. }
  83.  
  84. int
  85. get_name_width(w)
  86.     Widget w;
  87. {
  88.     Arg args[1];
  89.     Dimension width;
  90.     Widget name;
  91.  
  92.     name = XtNameToWidget(w, NAME);
  93.     XtSetArg(args[0], XtNwidth, &width);
  94.     XtGetValues(name, args, ONE);
  95.     return (int) width;
  96. }
  97.  
  98.  
  99. void
  100. set_value(w, new_value)
  101.     Widget w;
  102.     const char *new_value;
  103. {
  104.     Arg args[1];
  105.     Widget val;
  106.     
  107.     val = XtNameToWidget(w, VALUE);
  108.     XtSetArg(args[0], XtNlabel, new_value);
  109.     XtSetValues(val, args, ONE);
  110. }
  111.  
  112. void
  113. set_value_width(w, new_width)
  114.     Widget w;
  115.     int new_width;
  116. {
  117.     Arg args[1];
  118.     Widget val;
  119.     
  120.     val = XtNameToWidget(w, VALUE);
  121.     XtSetArg(args[0], XtNwidth, new_width);
  122.     XtSetValues(val, args, ONE);
  123. }
  124.  
  125. int
  126. get_value_width(w)
  127.     Widget w;
  128. {
  129.     Arg args[1];
  130.     Widget val;
  131.     Dimension width;
  132.  
  133.     val = XtNameToWidget(w, VALUE);
  134.     XtSetArg(args[0], XtNwidth, &width);
  135.     XtGetValues(val, args, ONE);
  136.     return (int) width;
  137. }
  138.  
  139. /* Swap foreground and background colors (this is the best I can do with */
  140. /* a label widget, unless I can get some init hook in there).         */
  141. void
  142. hilight_value(w)
  143.     Widget w;
  144. {
  145.     Arg args[2];
  146.     Widget val;
  147.     Pixel fg, bg;
  148.  
  149.     val = XtNameToWidget(w, VALUE);
  150.     XtSetArg(args[0], XtNforeground, &fg);
  151.     XtSetArg(args[1], XtNbackground, &bg);
  152.     XtGetValues(val, args, TWO);
  153.  
  154.     XtSetArg(args[0], XtNforeground, bg);
  155.     XtSetArg(args[1], XtNbackground, fg);
  156.     XtSetValues(val, args, TWO);
  157. }
  158.  
  159.